/*
* Author: Dzlua
* QQ    : 505544956
* time  : 2017/08/06
*/

#include <dzlua.h>
#include <iostream>



/*
*   -1  : low
*    0  : normal
*    1  : high
*/
dzlua::thread::Priority ts_priority(int8_t priority) {
    switch (priority) {
        case 0: return dzlua::thread::Priority::normal;
        case 1: return dzlua::thread::Priority::high;
        case -1: return dzlua::thread::Priority::low;
    }
    return dzlua::thread::Priority::normal;
};

int main(int argc, char* argv[])
{
    dzlua::thread::PriorityPool pool(4);
    std::vector< std::future<int> > results;

    //---------------------- 0,  1, 2,  3, 4, 5,  6, 7, 8, 9,10,11,12,13,14,15, 16, 17, 18, 19
    int8_t prioritys[20] = { 0, -1, 1, -1, 0, 1, -1, 0, 1, 1, 1, 1, 1, 0, 0, 0, -1, -1, -1, 0 };

    for(int i = 0; i < 20; ++i) {
        results.emplace_back(
            pool.PostTask(
                  ts_priority(prioritys[i])
                , [i]() {
                    std::cout << "-" << i << "-";
                    std::this_thread::sleep_for(std::chrono::milliseconds(500));
                    return i;
                } ) );
    }

    std::cout << "-------------" << std::endl;

    for(auto && result: results)
        std::cout << '|' << result.get() << '|';
    std::cout << std::endl;
    
    return 0;
}